<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="button" class="button">点击我</button>
    <div>
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
    </div>
  </body>
  <script>
    // for (let i = 1; i <= 100; i++) {
    //   const can3 = i % 3 === 0;
    //   const can5 = i % 5 === 0;
    //   if (can3 && !can5) {
    //     console.log(i);
    //   }
    // }
    // const button = document.querySelector("button");
    // const button2 = document.querySelector("#button");
    // const button3 = document.querySelector(".button");
    // button.addEventListener("click", () => {
    //   alert("按钮被点击了！");
    // },false);
    // 获取dom
    const divArr = document.querySelectorAll("div");
    // 遍历dom
    divArr.forEach((domItem) => {
      // 给每一个dom添加点击事件
      domItem.addEventListener("click", (e) => {
        alert(e.target.textContent);
      });
    });
  </script>
</html>
